using System;
using System.Collections.Generic;
using System.Text;
using IGGCore;

namespace IGGConsole
{
    public class ModeSummaryFormatter : ModeGameFormatterBase
    {
        #region IModeFormatter Members

        public override void FormatMode(Scoreboard board)
        {
            if (board.SelectedGame == null)
            {
                return;
            }
            Game game = board.SelectedGame;
            if (game.Linescore != null)
            {

                ShowBoxscore(game);
                Console.WriteLine();
            }
            else
            {
                ShowGamePreview(game);
                Console.WriteLine();
            }
            if (game.Status.Indicator.IsInProgress)
            {
                string battingTeam = game.AwayTeam.Abbrv;
                string pitchingTeam = game.HomeTeam.Abbrv;
                if (game.Status.InningTop == false)
                {
                    battingTeam = game.HomeTeam.Abbrv;
                    pitchingTeam = game.AwayTeam.Abbrv;
                }

                int len = game.Status.CurrentBatter.PartialName.Length;
                if (game.Status.CurrentPitcher.PartialName.Length > len)
                {
                    len = game.Status.CurrentPitcher.PartialName.Length;
                }
                len += 2;

                Console.WriteLine(" " + "Batting  "
                    + ToolBox.GetFormattedStringPadRight(battingTeam, 4)
                    + ToolBox.GetFormattedStringPadRight(game.Status.CurrentBatter.PartialName, len)
                    + game.Status.CurrentBatter.Hits + "/"
                    + game.Status.CurrentBatter.Ab + " "
                    + game.Status.CurrentBatter.AVG + " "
                    + game.Status.CurrentBatter.Homeruns + " hr "
                    + game.Status.CurrentBatter.RBI + " rbi"
                    );
                Console.WriteLine(" " + "Pitching "
                    + ToolBox.GetFormattedStringPadRight(pitchingTeam, 4)
                    + ToolBox.GetFormattedStringPadRight(game.Status.CurrentPitcher.PartialName, len)
                    + game.Status.CurrentPitcher.IP + " "
                    + game.Status.CurrentPitcher.ERA + " "
                    + game.Status.CurrentPitcher.Wins + "-"
                    + game.Status.CurrentPitcher.Losses);
                Console.WriteLine();
                Console.WriteLine(" " + FormatPBP(game.Status.LastPbp));
                Console.WriteLine();
                ShowLoadedBases(game);
                Console.WriteLine();
                ShowDeckHole(game, battingTeam);
            }
            else if (game.Status.Indicator.IsTerminated)
            {
                Console.Write(" W: " + game.Status.WinningPitcher.PartialName);
                Console.Write(" (" + game.Status.WinningPitcher.Wins + "-"
                    + game.Status.WinningPitcher.Wins + ", " + game.Status.WinningPitcher.ERA + ");");
                Console.Write(" L: " + game.Status.LosingPitcher.PartialName);
                Console.Write(" (" + game.Status.LosingPitcher.Wins + "-"
                    + game.Status.LosingPitcher.Wins + ", " + game.Status.LosingPitcher.ERA + ")");
                Console.WriteLine();
                if (game.Status.SavingPitcher != null && game.Status.SavingPitcher.Saves > 0)
                {
                    Console.Write(" S: " + game.Status.SavingPitcher.PartialName);
                    Console.Write(" (" + game.Status.SavingPitcher.Saves + ")");
                    Console.WriteLine();
                }

                ShowHomeRuns(game);
            }
            else if (game.Status.Indicator.IsInterrupted)
            {
                Console.WriteLine(" It is currently raining at " + game.Stadium.Name);
            }
        }


        #endregion
    }
}
